import re

# 检查密码是否满足安全要求
def check_password(password):
    # 检查长度是否在 8 到 16 之间
    if len(password) < 8 or len(password) > 16:
        return "No"
    
    # 使用集合来跟踪字符类别
    categories = set()
    for char in password:
        if char.islower():
            categories.add(2)  # 小写字母
        elif char.isupper():
            categories.add(1)  # 大写字母
        elif char.isdigit():
            categories.add(3)  # 数字
        else:
            categories.add(4)  # 特殊字符
    
    # 至少包含三种类别即为安全密码
    return "Yes" if len(categories) >= 3 else "No"

# 生成对应的 .out 文件
def generate_output_files(num_files=5):
    for i in range(1, num_files + 1):
        input_filename = f"{i}.in"
        output_filename = f"{i}.out"
        
        with open(input_filename, 'r') as infile, open(output_filename, 'w') as outfile:
            # 读取组数
            n = int(infile.readline().strip())
            results = []
            
            # 读取每个密码并检查安全性
            for _ in range(n):
                password = infile.readline().strip()
                results.append(check_password(password))
            
            # 写入检查结果到 .out 文件
            outfile.write("\n".join(results) + "\n")
        
        print(f"已生成文件: {output_filename}")

# 生成多个 .out 文件
generate_output_files(num_files=5)
